package org.dreamwork.jasmine2.util;

import org.dreamwork.jasmine2.javac.IClasspathBuilder;

import javax.servlet.ServletContext;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-4-9
 * Time: 下午6:02
 */
public class ClasspathBuilderFactory {
    private static DefaultClasspathBuilder dcb = null;
    private static WebSphereClasspathBuilder wscb = null;

    public static IClasspathBuilder newClasspathBuilder (ServletContext application) {
        if (ServerDetector.isWebSphere ())
            return getWebSphereClasspathBuilder (application);

        if (ServerDetector.isJBoss ())
            return new JBossClasspathBuilder (application);

        return getDefaultClasspathBuilder ();
    }

    private static DefaultClasspathBuilder getDefaultClasspathBuilder () {
        if (dcb == null)
            dcb = new DefaultClasspathBuilder ();
        return dcb;
    }

    private static WebSphereClasspathBuilder getWebSphereClasspathBuilder (ServletContext application) {
        if (wscb == null)
            wscb = new WebSphereClasspathBuilder (application);
        return wscb;
    }
}